﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace PRE.Register
{
    public partial class FrmCapchungchi : DevExpress.XtraEditors.XtraForm
    {
        DAL.EntitesDAL.LophocDAL _dal = new DAL.EntitesDAL.LophocDAL();
        DAL.EntitesDAL.KhoahocDAL _dal1 = new DAL.EntitesDAL.KhoahocDAL();
        
        public FrmCapchungchi()
        {
            InitializeComponent();
        }

        private void FrmCapchungchi_Load(object sender, EventArgs e)
        {
            DataTable tmp = _dal1.Select_Current(DateTime.Now);
            DataTable dtb = _dal.Select_Chungchi(tmp.Rows[0]["Makhoa"] + "");

            if (dtb != null)
                cboLophoc.Properties.DataSource = dtb;

            cboLophoc.ItemIndex = -1;
        }

        private void btnCapchungchi_Click(object sender, EventArgs e)
        {
            string _malop = cboLophoc.EditValue + "";
            string _trinhdo = _malop.Substring(3, 1);
            var ok = _dal.SetDacap(_malop);
            if (ok)
            {
                var frm = new Report.FrmReport_Base();
                frm.Text = "In: " + Text;
                var rpt = new Report.XRChungchi();
                rpt.lbTrinhdo.Text = _trinhdo;

                rpt.DataSource = _dal.Select_InChungchi(_malop);
                frm.SetReport(rpt);
                frm.Show();
                frm.Activate();
            }
            else 
            {
                MessageBox.Show("Lỗi! Vui lòng kiểm tra lại thông tin", "Thông Báo",MessageBoxButtons.OK,MessageBoxIcon.Error);
            }

        }

        private void btnDong_Click(object sender, EventArgs e)
        {
            this.Close(); 
        }

        private void cboLophoc_EditValueChanged(object sender, EventArgs e)
        {
            DataTable dtb = _dal.Select_Capchungchi(cboLophoc.EditValue.ToString());
            if (dtb != null)
                grcMain.DataSource = dtb;
        }
    }
}